package com.ruoyi.hospital.controller.storeInfo;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.storeInfo.PharmacyHerb;
import com.ruoyi.hospital.service.storeInfo.IPharmacyHerbService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 中草药信息Controller
 * 
 * @author wendao
 * @date 2024-08-19
 */
@RestController
@RequestMapping("/hospital/pharmacyHerb")
public class PharmacyHerbController extends BaseController
{
    @Autowired
    private IPharmacyHerbService pharmacyHerbService;

    /**
     * 查询中草药信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyHerb:list')")
    @GetMapping("/list")
    public TableDataInfo list(PharmacyHerb pharmacyHerb)
    {
        startPage();
        List<PharmacyHerb> list = pharmacyHerbService.selectPharmacyHerbList(pharmacyHerb);
        return getDataTable(list);
    }

    /**
     * 导出中草药信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyHerb:export')")
    @Log(title = "中草药信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PharmacyHerb pharmacyHerb)
    {
        List<PharmacyHerb> list = pharmacyHerbService.selectPharmacyHerbList(pharmacyHerb);
        ExcelUtil<PharmacyHerb> util = new ExcelUtil<PharmacyHerb>(PharmacyHerb.class);
        util.exportExcel(response, list, "中草药信息数据");
    }

    /**
     * 获取中草药信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyHerb:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(pharmacyHerbService.selectPharmacyHerbById(id));
    }

    /**
     * 新增中草药信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyHerb:add')")
    @Log(title = "中草药信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PharmacyHerb pharmacyHerb)
    {
        return toAjax(pharmacyHerbService.insertPharmacyHerb(pharmacyHerb));
    }

    /**
     * 修改中草药信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyHerb:edit')")
    @Log(title = "中草药信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PharmacyHerb pharmacyHerb)
    {
        return toAjax(pharmacyHerbService.updatePharmacyHerb(pharmacyHerb));
    }

    /**
     * 删除中草药信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyHerb:remove')")
    @Log(title = "中草药信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(pharmacyHerbService.deletePharmacyHerbByIds(ids));
    }
}